package org.dizem.minichat.model;

import org.dizem.minichat.util.DBUtil;

/**
 * User: DIZEM
 * Time: 11-3-26 下午4:46
 */

/**
 * User Operation
 */
public class UserDAO {

	/**
	 * Add an user to database
	 * @param user 	user to be added
	 * @return if added successfully
	 */
	public static boolean addUser(User user) {
		int result = DBUtil.update("insert into Tab_User values(?,?,?,?,?)",
				user.getId(), user.getPassword(), user.getNick(),
				user.getSex(), user.getAbout(), user.getEmail(), user.getAge());
		return result > 0;
	}

	/**
	 * Remove an user from database
	 * @param id 	id of an user to be removed
	 * @return if removed successfully
	 */
	public static boolean removeUser(int id) {
		int result = DBUtil.update("delete from Tab_User where id=?", id);
		return result > 0;
	}

	/**
	 * Find an user from database
	 * @param id 	id of an user to be find
	 * @return if find successfully
	 */
	public static User getUser(int id) {
		return (User) DBUtil.getData(User.class, "select * from Tab_User where id=?", id);
	}

	public static void main(String[] args) {
		System.out.println(getUser(10000));
	}
}
